Skip to content

server: reconfigure grows or shrinks the contexts live, on the s4 integration branch (S2 port of #104) - #105

Draft
joelteply wants to merge 14 commits into
codex/s4-per-mind-integrationfrom
fable/reconfigure-live-on-s4
Draft

joelteply wants to merge 14 commits into
codex/s4-per-mind-integrationfrom
fable/reconfigure-live-on-s4

Conversation

@joelteply

@joelteply joelteply commented Nov 10, 2026 •

Copy link
Copy Markdown

The S2 live reconfigure (#104, kept as the reference), ported onto codex/s4-per-mind-integration, the branch the core pins.

Commits

  1. -Werror fix on the s4 head (2390534), in its own commit. CI found three errors: server-train.cpp:1058 and server-context-learn.inc:396 (missing-field-initializers), and server-context-learn-checkpoint.inc:45-46 (ignored-attributes on decltype(&fclose)).
  2. server: reconfigure grows or shrinks the contexts live; the weights are never reloaded (S2) #104's commits, cherry-picked. s4 had not touched the load path, so the lifetime split merged as is. The learning check is rewritten for s4's learn duties (below).
  3. The live geometry everywhere it is read, and its cost reported:
    • HTTP-thread readers read the live geometry: the n_cmpl bound and infill's window.
    • get_slot_by_id no longer wraps (id % n_slots). After a shrink, the wrap ran a request for a parked slot on another mind's slot. A parked id now waits for its own slot, and an unknown id gets a 400.
    • /props reconfigure.cost reports rebuilds, pause ms (total, max, per 1k tokens held), tokens and bytes paged, and the context buffers per type.

Learning across a reconfigure. Both refusals are typed and owned by server-context-learn.inc (learning_blocks_reconfigure):

  • learn_in_progress. A learn's graph and accumulators live in the serving context until its restoration ends. The caller retries after.
  • learning_bound. Shadow optimizers are present (measured with llama_opt_visit_memory), or the training workspace still replaces the serving scheduler.

The optimizer state is per shadow (per mind's adapter), not per sequence, and it lives in the context. The fork moves it only through llama_opt_shadow_state_write plus llama_opt_prepare_restore and llama_opt_state_restore. The prepare step needs the shadow's retained labelled experience on a fresh context, and a reconfigure has none. So the mover cannot page it.

Update 2026-11-14: merged up to the s4 head (399383c). The shrink's freed bytes are now read live.

  • Merge (51c7557). s4 had 34 new commits. The conflicts were the -Werror fixes, which both sides had made (s4's form kept), and the task enum, which keeps both PROMPT_CACHE_LIMIT and RECONFIGURE. s4's n_ctx_slot capping auto-merged into build_contexts, so a reconfigure recomputes it.

  • CI subtracts (f121c00). s4's server jobs pass the whole suite (server: no adapter set starves another; the longest-unserved slot's set holds the batch #117), so the separate "Reconfigure tests" step, which ran the file twice, is removed.

  • Live memory report (3be88e8):

    • /props memory_breakdown was the load's snapshot, so it went stale at the first reconfigure. It now comes from the live allocator, through one reader (memory_breakdown_report) for the load and every reconfigure.
    • cost.context_buffers was a partial copy of that report and is removed.
    • context_geometry.max_tokens_per_sequence is n_ctx_slot.
  • Validator (test_a_shrink_gives_the_kv_memory_back_and_a_grow_takes_it_again). It holds four states and shrinks from 1,024 to 256 cells. It asserts that:

    • the KV bytes fall to exactly cells x bytes-per-cell;
    • context plus compute falls, and the weights are unchanged;
    • the grow back takes the same bytes, with next tokens identical to the control.

    The 100-cycle test now also asserts that the bytes end exactly where they started.

Why now. On the M5 the engine's KV pool (4.26 GB) and Metal graph (3.03 GB) are allocated for the launch geometry and never returned, while the host sits at 0.1 GB free. This verb is how the core gives them back without a relaunch. The design note is in continuum docs/architecture/CONTINUUM-ENGINE.md, "S2 status, 2026-11-14".

Unproven on hardware. CI runs on CPU only. The Metal receipt (vm_stat wired GB before and after a shrink on the M5) is owed after the pin bump is deployed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply and others added 7 commits November 10, 2026 11:12
The warnings CI's -Werror made fatal at 2390534:
- server-train.cpp:1058, examples/training/finetune.cpp:80 and finetune-lora.cpp:139
  -Werror=missing-field-initializers: llama_opt_params gained static_admission(_data) and
  workspace_admission(_data); none of these callers owns allocation authority, so they
  are null
- server-context-learn.inc:396 -Werror=missing-field-initializers: pending_learn is
  value-initialized and its fields named, instead of an aggregate list that ran out
  before failure, finished and grant
- server-context-learn-checkpoint.inc:45-46 -Werror=ignored-attributes: the FILE handles
  close through a deleter type, not decltype(&fclose)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…re never reloaded

POST /reconfigure {"n_ctx", "n_seq"} rebuilds the target and draft contexts at the
task-phase safe point (no llama_decode in flight, the SLOT_SAVE argument): every slot
holding state is paged out, unfinished generations included, the contexts are rebuilt
on the same model, and every state that fits is paged back in, so each generation
continues from its next token with its host-side sampler. Nothing is cancelled; new
work waits in the queue. Grow and shrink are one path (SERVING-ENGINE.md, S2).

- the lifetimes split: common_init_result and common_speculative_init_result create
  their context in init_context() apart from the model; the server's load_model is
  load_weights + build_contexts and destroy is destroy_contexts + free_weights
- server-slot-page.{h,cpp}: the one state mover (llama_state_seq_get/set_data for the
  target and draft); the prompt cache's save and load, the reconfigure and the saved
  page's checkpoint sidecar all go through it
- server-reconfigure.{h,cpp}: the logic, typed (Geometry in, Applied or Refused out),
  against an engine the server context implements; JSON only at the HTTP edge
- shrink never truncates: a slot past a smaller n_seq, or a state the pool cannot hold,
  is parked whole and named (slot, tokens_held, tokens_fit); a later reconfigure that
  holds it places it back. A KV cache type change is refused by name.
- /props reports the live geometry, the weight-load counter and the last outcome's cost
  (pause ms against tokens held)
- tests/unit/test_reconfigure.py: generations in progress finish token-identical across
  a reconfigure; 100 grow/shrink cycles keep every state and never reload the weights;
  queued requests all complete; a shrink names the slots it paged out

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…c, as the fork's learn members do

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…in one batch, so the control groups every step alike

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…t context

A backend sampler chain is initialized once, for the context it was first attached
to (llama_sampler_chain_backend_init asserts "called twice"); re-attaching the live
chain after a reconfigure aborted the server under LLAMA_ARG_BACKEND_SAMPLING=1.
The slot now gets a fresh chain from its task's params with the old chain's state
copied in (common_sampler_copy, as a speculative rollback does), then attaches it.
The reconfigure tests print the server's log when they fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…params (common_sampler_init takes them mutable)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…slot; /props prices a reconfigure

- n_cmpl is bounded by the slots served now (eval_llama_cmpl_schema takes the live count),
  and infill frames its prompt to the live window, not the load's snapshot
- get_slot_by_id no longer wraps (id % n_slots): after a shrink that sent a request for a
  parked slot to another mind's live slot. An id out of range is no slot: a parked id waits
  for its own slot to return, an id nothing has is refused (400)
- /props reconfigure.cost: rebuilds, pause ms (total, max, per 1k tokens held), tokens and
  bytes paged, the last outcome, and the context buffers the state lives in, per type
- tests: a request for a parked slot waits and never touches slot 1; n_cmpl follows a grow
  and a shrink; the cost counts only rebuilds

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply force-pushed the fable/reconfigure-live-on-s4 branch from 239f27e to 757fd0d Compare November 10, 2026 17:12
…ting failures stop the suite before them

On this branch's head the server suite stops under -x before unit/test_reconfigure.py:
the dream step's /lora-adapters/fresh and unit/test_lora.py are refused "unknown_residency"
(they send no residency, which b8513d9 made required), and test_completion_unified is
timing-dependent. This step runs the validator on its own (plain and backend sampling on
ubuntu). Drop it once the suite reaches the file again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
joelteply and others added 3 commits November 14, 2026 06:51
s4's context_geometry capping (n_ctx_slot) lands in build_contexts, so a reconfigure recomputes it;
the -Werror fixes both sides made take s4's form; the task enum keeps PROMPT_CACHE_LIMIT and RECONFIGURE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
… goes

s4's server jobs pass the whole suite now (PR #117: ubuntu 11m56s, windows 15m22s green), so
unit/test_reconfigure.py is reached under -x like every other test file and the extra step ran it twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…n /props

/props memory_breakdown was the load's snapshot, so after the first reconfigure it named buffers that
no longer existed. One reader (memory_breakdown_report) now serves the load's meta and every published
geometry, and /props answers with the live one. cost.context_buffers was a partial copy of it and goes.
context_geometry.max_tokens_per_sequence is n_ctx_slot (capped at n_ctx_train), the size the slots
enforce, as s4's load-time report already says.

Validator (test_reconfigure.py): a shrink from 1024 to 256 cells with four held states frees the KV
pool to exactly cells x bytes-per-cell, lowers context+compute, keeps the weights, and a grow takes the
same bytes back with every state's next tokens identical to an unreconfigured control; 100 grow/shrink
cycles end at the exact bytes they started at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…he live reconfigure (S2)

Conflicts resolved:
- server-test-faults.h: both hooks kept (this line's step_delay_ms, #118's page_io_gate); any() and the
  startup log name both.
- server-context.cpp: slots are created by bind_slots() (a reconfigure re-binds them), so the integration's
  inline slot setup goes; its page-io pool is created beside bind_slots; the trace/debug/test-fault reads
  stay where this line moved them (load()). SLOT_SAVE takes #118's page_save / page_restore /
  page_io_done (off the task loop); those resolve slots through get_slot_by_id, which this line made
  exact (a parked id is never another mind's slot).

Receipt (qwen35-0.8b, M5, 2026-11-16, this merge): 0 build warnings; 20 live reconfigures cycling
(16384,4) (4096,1) (12288,3) (8192,2) for (n_ctx, n_seq): a temperature-0 reply identical before and
after, the weights loaded once (one load in the log), RSS 1,098 MB before and 1,167 MB after (+69 MB;
not claimed flat).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Author

Independent review exact907510d241b6711251d40349c95bc6a7c44e7db3: BLOCK (P1).

Shrinking n_ctx without reducing n_seq can park a state and leave an empty live placeholder at the same ID. Explicit/LRU selection do not exclude this in-range parked ID. New work can occupy it, preventing original restoration; subsequent parking hits duplicate-ID assertion. Exclude all parked IDs from admissions, including placeholders. Add same-n_seq shrink, explicit+automatic request, subsequent shrink/grow regression.

Native KV remains native and learning refusals protect retained learning state. Allocator report does not include all parked host/draft memory; Metal physical memory-return proof remains owed. Windows Server context-limit failure remains a gate. New Python validators conflict with the user's no-Python requirement; use native regression tooling. Reviewer identity_crypto_review; no builds/deployment performed.

… decision over a typed view (Codex's review of #105)

A shrink with the same n_seq parks a mind and leaves an empty placeholder at its in-range id. get_slot_by_id
returned that placeholder, and the similarity and LRU choices could pick it (it is idle, empty and the least
recently used), so another request took the id and the parked mind could not come back (or a second park of
the id asserted).

- server-slot-pick.h: server_pick_slot(view, id, n_task_tokens, similarity) -> by_id / by_prefix / by_lru /
  wait / no_slot. A parked id is never chosen: a task naming it waits, an anonymous task never lands on it.
  get_available_slot builds the view (computing the prefix only for slots it could pick) and follows the
  decision; its three inline loops are gone.
- get_slot_by_id returns no slot for a parked id (slot actions and explicit requests never touch the
  placeholder).

Tests: test-server-slot-pick (model-free): LRU and prefix choices skip the parked placeholder, a request naming
it waits, an unknown id is no_slot; shrink -> requests (the live free slots fill, the rest wait, id 2 untouched)
-> grow (the mind's request runs on its own id). Server suites on this build (qwen-tiny fixtures): reconfigure,
completion and slot-save 57 passed, 6 skipped (one HF-download test deselected: this build has no curl).
0 warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Author

Re-review105 exact48c09a05ae8ae7f998a5c8264d631f8f64f61624 BLOCK: get_free_slots still admits childfanout by !is_processing andparentexclusion, notparked; n_cmpl>1 can occupy parkedplaceholder. Guard everyactualcaller and test realshrink/fanout/grow custody. Newby_id also leavesupdate_cache=false unlike previouslowprefix save/restore; preserve untilnamedpagepath actuallyreplaces it, or explicitlyreview removal. Pureviewtest doesnotproveKVstatepreservation. Reviewer identity_crypto_review; CI/hardwareproofpending.

…s cache save; slot views live in reused storage (Codex's second review of #105; Joel: allocation is the enemy)

- server_slot_free is the one predicate; server_pick_free_slots (a parent's children) uses it, so the fan-out
  never hands out a parked placeholder. It writes indices into caller storage and returns a count.
- by_id keeps upstream's behaviour: a named slot whose prompt clears the similarity floor but keeps under
  half of its context saves that context to the prompt cache first (the prefix is measured for it).
- The per-slot view is server-owned storage, cleared and refilled per choice: no allocation once it reached
  the slot count (it was a fresh vector per task). get_free_slots still returns upstream's vector of slot
  pointers to the existing launch path.

Tests: test-server-slot-pick adds the fan-out case (exclude the parent; only the free live slot, never the
parked id). Server suites on this build: reconfigure, completion and slot-save 56 passed, 7 skipped (one
HF-download test deselected). 0 warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Author

Re-review exactd89fa9a82b4bd600c8a990aaa4cfea8cafb74428: prior parkedfanout and explicitlow-prefix cache source blockers addressed. Actual get_free_slots now uses shared !processing&&!parked predicate; explicitselection retains low-keep update_cache condition; scratchview is serverowned. Sourceapproval conditional exactCI; pureviewregression is not proof of actualKV/sampler preservation, so real shrink/fanout/grow state replay and Metal memory-return evidence remain deployment gates. PriorWindows context-limit failure mustbe resolved/classified with evidence, not ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant